﻿<?php
require_once(dirname(__FILE__)."/../../libs/login/login.php");  
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../../admin/libs/product_class.php");
require_once(dirname(__FILE__)."/../../admin/libs/shuxing_class.php");
$lg=new login();
$lg->checklogin("admin_member");//检验是否登录
$mc=new libstr();
$pd=new product();
$sx=new shuxing();
//
//获得属性
$allsx=$sx->getshuxingtype();
//print_r($allsx);
$total=count($allsx);
for($i=0;$i<$total;$i++){
$tb=$allsx[$i]["ziduan"]."_class";
$allsx[$i]["list"]=$sx->getshuxinglist($tb);//获得属性选择选项
}
//print_r($allsx);
//上传产品
if($mc->Ismp($_POST['addbtn'])!="")
{
$topicname=$mc->request("topicname","");
if($topicname==""){$mc->msg("产品名称不能为空！");}
$codeid=$mc->request("codeid",0);
$cataid=$mc->request("cataid","");
if($cataid==""){$mc->msg("请选择产品类别！");}
if($pd->myck($cataid)=='true'){$mc->msg("产品类别存在子类，请选择此类别的最底层子类作类别！");}

//提交所有属性
$shuxing=array();//数组类型
for($z=0;$z<$total;$z++){ 
	$name=$_POST["shuxing".$allsx[$z]["id"]];
	if(count($_POST[$name])>0){
	$values=sprintf("%s",implode("|", $_POST[$name]));
	}else{
	$values="";	
	}
	if($name!=""){
$shuxing[$z]["name"]=$name;	
$shuxing[$z]["value"]=$values;
	}
}
//print_r($shuxing);
//exit();

$content=$mc->request("content","");
$biaoqian=$mc->request("biaoqian","");
$keyword=$mc->request("keyword","");
$guanlian=$mc->request("guanlianid",0);
$pic=$mc->request("pic","");
$durl=$mc->request("durl","");
$filedaxiao=$mc->request("filedaxiao",0);
$isshow=1;
$adduserno=$lg->getsession("admin_member","userno");

$pd->product_add($topicname,$codeid,$cataid,$guanlian,$shuxing,$content,$biaoqian,$keyword,$pic,$durl,$filedaxiao,$adduserno,$isshow);
$mc->msg("数据成功保存","product_list.php?classid=".$_POST["cataid"]);//成功返回列表页
}
$path="产品添加";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理系统</title>
<link rel="stylesheet" type="text/css" href="../../plug/swfupload/uploadify.css">
	<link href="../css/css.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="../../plug/kindeditor/themes/default/default.css" />
	<link id="artDialog-skin" href="../../plug/art/skins/chrome.css" rel="stylesheet" />
	<!--产品图片css!-->
	<style>
.imgall{position: relative; width:100px; height:100px; float:left; margin-right:10px}

.imgall img{  }
.imgall span{ position:absolute; width:100px; height:32px;bottom:0px; display:none; }
.imgall:hover span{display:block;}
.imgall span input{float:right; cursor:pointer; background-image: url(../images/trash-alt-empty-32.png); width:32px; height:32px; border:0; }
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script src="../../plug/art/artDialog.js" type="text/javascript"></script>
<script src="../../plug/art/plugins/iframeTools.source.js"></script>
<script charset="utf-8" src="../../plug/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="../../plug/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="../../plug/swfupload/jquery.min.js"></script>
<script type="text/javascript" src="../../plug/swfupload/jquery.uploadify-3.1.min.js"></script>
<script>
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			allowFileManager : true
		});
		
	});
</script>

<script type="text/javascript">
	  //图片上传
	$(document).ready(function() {
        $('#file_upload').uploadify({
            'onSelect' :function(){shows3();},
			'onUploadSuccess' : function(file, data, response) {  
 		     // alert(data);
			  var board=document.getElementById("pic0");
			  if(board.value!='')
			  {
			  	  $("#allpics").append("<div class='imgall'><img src='"+data+"' width='100' height='100' /><span><input type='button' title='删除'></span></div>");
				  board.value=board.value+','+data;
			  }else
			  {
			  	 $("#allpics").html("<div class='imgall'><img src='"+data+"' width='100' height='100' /><span><input type='button' title='删除'></span></div>");
			      board.value=data;
			  }
			  
			//成功后加载	删除修改图片代码		  
			$(".imgall input").each(function(i){
				$(this).click(function(){
					$(this).parent().parent().remove();
					var im="";
					$(".imgall").each(function(index){
						
						if(im==""){
							im=$(".imgall img:eq("+index+")").attr('src');
							}else{
							im+=","+$(".imgall img:eq("+index+")").attr('src');	
							}
					})
					  board.value=im;
					  if(im==""){
						 $("#allpics").html('<img src="../../plug/swfupload/moren.jpg" height="90px" >');//如果为空，显示默认的图片
					   }
				})	
			})	  
		}, 	
			

		'onUploadStart' : function(file) {
		$("#file_upload").uploadify("settings","formData",{"pic1":$("#aaa").val()});
		},	
		
		'removeTimeout':'6',//进度条消失时间
		'method'   : 'post',
		'buttonImage':'',					
		'height': '30',
		'width': '75',
		'queueID' : 'some_file_queue',
		'displayData'    : 'percentage',
		'fileTypeExts'     : '*.jpg;*.jpeg;*.png;*.gif;*.bmp',
		'fileTypeDesc'    : '支持的格式(.JPG,.JPEG,.PNG,.GIF,.BMP)',//允许的格式
		'fileSizeLimit':'100024KB',//上传文件大小限制
		'queueSizeLimit':'10',//同时上传的文件最大数
		//'auto':false,//是否选取文件后自动上传
		'swf' : '../../plug/swfupload/uploadify.swf?ver='+ Math.random(),//是组件自带的flash，用于打开选取本地文件的按钮 
		'uploader' : '../../plug/swfupload/poster.php?type=1',
		'buttonText': '上传图片'	 
		// Your options here
     });		
});	
	//$('#file_upload').uploadify('upload','*')//控制文件上传		
</script>



  <script type="text/javascript">
  //判断是否为底层类
  function ischild(id){
  	$.ajax({ 
        type: "POST", 
        url: "../ajax/inc.php", 
        dataType: "text", 
        data: {"isbtn":true,"id":id}, 
 success: function(data){
 	  if(data.indexOf("have child")!=-1)
  {
  	 alert("该类别存在子类，请选择此类别的最底层子类作类别");
	  return ;
  }
 }
  	})
  	
  }
  </script>
</head>
<body style="background:#fff"> 
<div class="content">
    <div class="right">
    <form action="" method="POST">
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="100%" height="24" class="top_head">&nbsp;</td>
          </tr>
          <tr>
            <td valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="1%" align="right"  height="45">&nbsp;</td>
                    <td width="99%" >
                     <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="55%" style="padding-left:20px;padding-top:10px;"><img src="../images/head.gif" width="13" height="11"><b><?php echo $path;?></b><a href="product_list.php?classid=<?php echo $_GET["classid"];?>" style=" margin-left:20px; text-decoration:underline;" >返回列表</a></td>
                        <td width="45%" align="right">&nbsp;</td>
                      </tr>
                    </table>
                    </td>
                  </tr>
                </table>
            </td>
          </tr>
   </table>
   
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="liebiao">
  <tr>
    <td width="11%" height="40" align="right" valign="middle">产品名称：</td>
    <td height="40" valign="middle">
      <input type="text" name="topicname" id="topicname" /> <font>（*产品名称不能为空）</font></td>
      <input type="hidden" name="codeid" id="codeid" value="<?php echo $pd->setcodeid();?>"/>
    </tr>
    <td align="right" valign="middle">产品类别：</td>
    <td valign="middle" style="padding-bottom:6px;"><div class="ziyuan">
      <select name="cataid" id="cataid" onchange="ischild(this.value)">
      <option value="">请选择类别</option>
       <?php 
		$db->depth=0;
		$twhere="";  
		$db->getchild("product_class",0,$mc->Ismp($_GET["classid"]),"ID","-",$twhere);
		?>
      </select>
    </div></td>
    </tr>
       <tr>
    <td width="11%" height="40" align="right" valign="middle">产品关联：</td>
    <td height="40" valign="middle">
      <input type="text" name="guanlianstr" id="guanlianstr" disabled style=" width:150px"/>&nbsp;<bdo> <input type="button" name="glbtn" id="glbtn" value="选择关联" onclick="art.dialog.open('guanlian_class.php',
    {title: '关联产品', width: 500, height:360});"/>&nbsp;<input type="button"  id="del" value="取消关联" onClick="document.getElementById('guanlianstr').value='',document.getElementById('guanlianid').value='0'"></bdo><font></font></td>
      <input type="hidden" name="guanlianid" id="guanlianid" value=""/>
    </tr>
    <?php foreach($allsx as $rs){?>

 <tr>
     <?php if(count($rs["list"])>0){?>
        <input type="hidden" name="shuxing<?php echo $rs["id"];?>" value="<?php echo $rs["ziduan"];?>">
    <td height="30" align="right" valign="middle"><?php echo $rs["classname"]?>：</td>

    <td height="30" valign="middle"><div class="kejian">
    <?php foreach ($rs["list"] as $rs1){?>
    <?php if($rs["xuanze"]==0){?>
      <input type="radio" name="<?php echo $rs["ziduan"]?>[]" value="<?php echo $rs1["rootid"]?>" /><!--单选!-->
      <?php }else{?>
        <input type="checkbox" name="<?php echo $rs["ziduan"]?>[]" value="<?php echo $rs1["rootid"]?>" /><!--多选!-->
      <?php }?>
      <span><?php echo $rs1["classname"]?></span>
    <?php }?>
    </div></td>
    </tr>
    <?php }?>
    <?php }?>
 
    
    
  <tr>
    <td height="auto" align="right" valign="top" style="padding-top:8px;">内容介绍：</td>
    <td height="auto" valign="top" style="padding-top:10px;padding-bottom:10px;"><textarea id="content" name="content" style="width:898px;height:415px;visibility:hidden;"></textarea></td>
    </tr>
<!--  <tr>
    <td height="40" align="right" valign="middle">标签：</td>
    <td height="40" valign="middle"><input type="text" name="biaoqian" id="biaoqian" /><font>（多个标签用空格隔开）</font></td>
    </tr>
  <tr>
    <td height="40" align="right" valign="middle">关键词：</td>
    <td height="40" valign="middle"><input type="text" name="keyword" id="keyword" /><font>（多个关键词用空格隔开）</font></td>
    </tr>
   <tr>-->
    <td height="40" align="right" valign="middle">产品图片：</td>
    <td height="40" valign="middle"><input type="text" name="pic" id="pic0" /><div class="anniu"><input type="file" name="file_upload" id="file_upload" /></div><font>（可输入图片路径，如：http://xx.com/xx.jpg，多张图片用 , 隔开）</font></td><!-- 这里的全屏id有影响!-->
    </tr>
     <tr>
    <td height="40" align="right" valign="middle">图片预览：</td>
    <td height="40" valign="middle"><div id="allpics"><img src="../../plug/swfupload/moren.jpg" height="90px"  ></div></td><!-- 预览的图片!-->
    </tr>
    <!--上传图片弹出对话框，显示上传的进度条!-->
    <div class="xz" id="Idiv3" style="display:none; z-index:100">
		<div class="xzleft"></div>
		<Div class="xzmid">
		  <h2>正在上传图片...</h2>
		  <p>最多上传5张图片，支持jpg,gif,png,jpeg,bmp格式</p>
		  <div id="some_file_queue"></div>
		  <Div class="anu"><input  type="button" onclick="$('#file_uploads3').uploadify('cancel','*');return closeDivs3()"  value="关闭" /></Div>
		</Div>
		<div class="xzright"></div>
		</div>
	</div>	


  <tr style="display:none">
    <td height="50" align="right" valign="middle">上传文件：</td>
    <td height="50" valign="middle"><input type="text" name="durl" id="durl" /><div class="anniu"> <input type="submit" name="button3" id="button3" value="上传文件" /></div></td>
    </tr>

	
  <tr  style="display:none">
    <td height="50" align="right" valign="middle">文件大小：</td>
    <td height="50" valign="middle"><span><input type="text" name="filedaxiao" id="daxiao" /></span><Font>（以KB为单位,该项不用填）</Font></td>
    </tr>
  <tr>
    <td height="50" align="right" valign="middle">&nbsp;</td>
    <td height="50" valign="middle"><bdo>
      <input type="submit" name="addbtn" id="addbtn" value="提交保存" />
    </bdo></td>
    </tr>
    </table>
    </from>
    </div>
        </div>

</body>
</html>

